package net.opslog.web.client.service;

import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.UrlBuilder;
import com.google.gwt.user.client.Window;

public class DefaultRequest {
	protected UrlBuilder url = new UrlBuilder();
	
	public DefaultRequest(){
		url.setHost(Window.Location.getHost());
		url.setProtocol(Window.Location.getProtocol());
	}
	
	protected void send(RequestCallback cb) {
		RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
				url.buildString());
		builder.setTimeoutMillis(10000);
		builder.setCallback(cb);

		Request req = null;
		try {
			req = builder.send();
		} catch (RequestException e) {
			cb.onError(req, e);
		}
	}

	public void setParameter(String parameter, String value) {
		url.setParameter(parameter, value);
	}
}
